using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Recorder;
using UnityEngine.Recorder.Input;

namespace UTJ.FrameCapturer.Recorders
{
	public abstract class BaseFCRecorderSettings : RecorderSettings
	{
		public override bool isPlatformSupported => Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.LinuxEditor || Application.platform == RuntimePlatform.LinuxPlayer;

		public override bool ValidityCheck(List<string> errors)
		{
			bool result = base.ValidityCheck(errors);
			if (string.IsNullOrEmpty(m_DestinationPath.GetFullPath()))
			{
				result = false;
				errors.Add("Missing destination path.");
			}
			if (string.IsNullOrEmpty(m_BaseFileName.pattern))
			{
				result = false;
				errors.Add("missing file name");
			}
			return result;
		}

		public override RecorderInputSetting NewInputSettingsObj(Type type, string title)
		{
			RecorderInputSetting recorderInputSetting = base.NewInputSettingsObj(type, title);
			if (type == typeof(CBRenderTextureInputSettings))
			{
				CBRenderTextureInputSettings cBRenderTextureInputSettings = (CBRenderTextureInputSettings)recorderInputSetting;
				cBRenderTextureInputSettings.m_FlipFinalOutput = true;
			}
			else if (type == typeof(RenderTextureSamplerSettings))
			{
				RenderTextureSamplerSettings renderTextureSamplerSettings = (RenderTextureSamplerSettings)recorderInputSetting;
				renderTextureSamplerSettings.m_FlipFinalOutput = true;
			}
			return recorderInputSetting;
		}

		public override List<InputGroupFilter> GetInputGroups()
		{
			List<InputGroupFilter> list = new List<InputGroupFilter>();
			list.Add(new InputGroupFilter
			{
				title = "Pixels",
				typesFilter = new List<InputFilter>
				{
					new TInputFilter<CBRenderTextureInputSettings>("Camera(s)"),
					new TInputFilter<RenderTextureSamplerSettings>("Sampling"),
					new TInputFilter<RenderTextureInputSettings>("Render Texture")
				}
			});
			return list;
		}

		public override bool SelfAdjustSettings()
		{
			if (base.inputsSettings.Count == 0)
			{
				return false;
			}
			bool result = false;
			if (base.inputsSettings[0] is ImageInputSettings)
			{
				ImageInputSettings imageInputSettings = (ImageInputSettings)base.inputsSettings[0];
				if (imageInputSettings.maxSupportedSize != EImageDimension.x4320p_8K)
				{
					imageInputSettings.maxSupportedSize = EImageDimension.x4320p_8K;
					result = true;
				}
			}
			return result;
		}
	}
}
